/*************************************************************************/
/*									 */
/*		Global data for C4.5					 */
/*		--------------------					 */
/*									 */
/*************************************************************************/

#include <cstdio>

namespace classifier_test
{

namespace c45r8
{

extern  short		MaxAtt,		/* max att number */
			MaxClass,	/* max class number */
			MaxDiscrVal;	/* max discrete values for any att */

extern  ItemNo		MaxItem;	/* max data item number */

extern  Description	*Item;		/* data items */

extern  DiscrValue	*MaxAttVal;	/* number of values for each att */

extern  char		*SpecialStatus;	/* special att treatment */

extern  String		*ClassName,	/* class names */
			  *AttName,	/* att names */
			  **AttValName,	/* att value names */
			FileName;	/* family name of files */

extern  Boolean		AllKnown;	/* true if there have been no splits
					   on atts with missing values above
					   the current position in the tree */


/*************************************************************************/
/*									 */
/*		Global parameters for C4.5				 */
/*		--------------------------				 */
/*									 */
/*************************************************************************/


extern  short		VERBOSITY,	/* verbosity level (0 = none) */
			TRIALS;		/* number of trees to be grown */

extern  Boolean		GAINRATIO,	/* true=gain ratio, false=gain */
			SUBSET,		/* true if subset tests allowed */
			BATCH,		/* true if windowing turned off */
			UNSEENS,	/* true if to evaluate on test data */
			PROBTHRESH;	/* true if to use soft thresholds */

extern  ItemNo		MINOBJS,	/* minimum items each side of a cut */
			WINDOW,		/* initial window size */
			INCREMENT;	/* max window increment each iteration */

extern  float		CF;		/* confidence limit for tree pruning */


// getnames
void Error(short n, String s1, String s2);
String CopyString(String x);
Boolean ReadName(FILE *f, String s);

// trees
void PrintTree(Tree T);
void SaveTree(Tree T, String Extension);
Tree CopyTree(Tree T);
int TreeSize(Tree Node);
void ClearTree(Tree Node);
void ReleaseTree(Tree Node);
Tree Leaf(ItemCount *ClassFreq, ClassNo NodeClass, ItemCount Cases, ItemCount Errors);
void Sprout(Tree Node, DiscrValue Branches);
void Indent(short Sh, char *Mark);
void Show(Tree T, short Sh);
short MaxLine(Tree St);
void ShowBranch(short Sh, Tree T, DiscrValue v);
void OutTree(Tree T);
void SaveDiscreteNames(void);
void StreamOut(String s, int n);
void RecoverDiscreteNames(void);
void StreamIn(String s, int n);

// besttree
void FormTarget(ItemNo Size);
void FormInitialWindow(void);
Tree Iterate(ItemNo Window, ItemNo IncExceptions);
void Shuffle(void);

// build
void InitialiseTreeData(void);
void InitialiseWeights(void);
Tree FormTree(ItemNo Fp, ItemNo Lp);
void Swap(ItemNo a,ItemNo b);
ItemCount CountItems(ItemNo Fp, ItemNo Lp);
ItemNo Group(DiscrValue V, ItemNo Fp, ItemNo Lp, Tree TestNode);

// prune
Boolean Prune(Tree T);
float EstimateErrors(Tree T, ItemNo Fp, ItemNo Lp, short Sh, Boolean UpdateTree);
void CheckPossibleValues(Tree T);

// classify
ClassNo Category(Description CaseDesc, Tree DecisionTree);
int Classify(Description CaseDesc, Tree T, float Weight);

// confmat
void PrintConfusionMatrix(ItemNo *ConfusionMat);

// subset
void EvalSubset(Attribute Att, ItemNo Fp, ItemNo Lp, ItemCount Items);
void SubsetTest(Tree Node, Attribute Att);
void Combine(DiscrValue x, DiscrValue y, DiscrValue Last);
void Uncombine(DiscrValue x, DiscrValue y);
void PrintSubset(Attribute Att, Set Ss);

// discr
void EvalDiscreteAtt(Attribute Att, ItemNo Fp, ItemNo Lp, ItemCount Items);
void DiscreteTest(Tree Node, Attribute Att);
void ComputeFrequencies(Attribute Att, ItemNo Fp, ItemNo Lp);
float DiscrKnownBaseInfo(ItemCount KnownItems, DiscrValue MaxVal);

// contin
void EvalContinuousAtt(Attribute Att, ItemNo Fp, ItemNo Lp);
void ContinTest(Tree Node, Attribute Att);
float GreatestValueBelow(Attribute Att, float t);

// info
float Worth(float ThisInfo, float ThisGain, float MinGain);
void ResetFreq(DiscrValue MaxVal);
float TotalInfo(ItemCount V[], DiscrValue MinVal, DiscrValue MaxVal);
float ComputeGain(float BaseInfo, float UnknFrac, DiscrValue MaxVal, ItemCount TotalItems);
void PrintDistribution(Attribute Att, DiscrValue MaxVal, Boolean ShowNames);

// sort
void Quicksort(ItemNo Fp, ItemNo Lp, Attribute Att, void (*Exchange)(int, int));

// stats
float AddErrs(ItemCount N, ItemCount e);

// st-thresh
void ScanTree(Tree T, ItemNo Fp, ItemNo Lp);

}

}
